package com.guchenbo.example.httpclient;

import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpUriRequest;

/**
 * @Author gucb
 * @Date 2017/9/1.
 */
public class BasicHttpClient {
    public static final String USER_AGENT_CHROME = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.101 Safari/537.36";

    protected HttpResponseCallBack callBack = new SimplePrintCallback();

    protected void setHeader(HttpUriRequest request) {
        if (request.getHeaders("Accept") == null || request.getHeaders("Accept").length == 0)
            request.setHeader("Accept", "*/*");

        if (request.getHeaders("User-Agent") == null || request.getHeaders("User-Agent").length == 0)
            request.setHeader("User-Agent", USER_AGENT_CHROME);
    }

    class SimplePrintCallback implements HttpResponseCallBack {

        @Override
        public void doAction(HttpResponse response) throws Exception {
            System.out.println(HttpUtils.toString(response.getEntity()));
        }
    }

    public enum Method {
        get,
        post;
    }
}
